package kd

import (
	"io/ioutil"
	"net/http"

	"github.com/gin-gonic/gin"
)

func GetPrintComponent(c *gin.Context) {
	printCodeCssByte, err1 := ioutil.ReadFile(printCodeCssPath)
	if err1 != nil {
		c.JSON(http.StatusOK, gin.H{
			"code" : 4003,
			"msg" : "代码高亮资源不存在！",
		})
		return
	}

	printHTMLCssByte, err2 := ioutil.ReadFile(printHTMLCssPath)
	if err2 != nil {
		c.JSON(http.StatusOK, gin.H{
			"code" : 4003,
			"msg" : "HTML头文件不存在！",
		})
		return
	}

	printPDFCssByte, err3  := ioutil.ReadFile(printPDFCssPath)
	if err3 != nil {
		c.JSON(http.StatusOK, gin.H{
			"code" : 4003,
			"msg" : "PDF打印样式不存在！",
		})
		return
	}

	printHeadHtmlByte, err4    := ioutil.ReadFile(printHeadHtmlPath)
	if err4 != nil {
		c.JSON(http.StatusOK, gin.H{
			"code" : 4003,
			"msg" : "HTML样式资源不存在",
		})
		return
	}

	demoMDByte, err5 := ioutil.ReadFile(demoMDPath)
	if err5 != nil {
		c.JSON(http.StatusOK, gin.H {
			"code" : 4003,
			"msg" : "Demo MD不存在",
		})
	}

	c.JSON(http.StatusOK, gin.H{
		"code" : 200,
		"data" : gin.H{
			"version" : KDVersion,
			"printCodeCss" :  string(printCodeCssByte),
			"printHTMLCss" :  string(printHTMLCssByte),
			"printPDFCss" :   string(printPDFCssByte),
			"printHeadHtml" : string(printHeadHtmlByte),
			"demoMD" : string(demoMDByte),
		},
	})
}